package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import controller.EmpController;
import entity.T_account;


@WebServlet("/AddEmpServlet")
public class AddEmpServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public AddEmpServlet() {
		super();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		EmpController controller = new EmpController();
		String name = request.getParameter("name");
		String number = request.getParameter("number");
		String money = request.getParameter("money");
		
		T_account emp = new T_account(0, name, number, money);
		int addAccount = controller.addAccount(emp);
		if (addAccount > 0) {
			response.sendRedirect("EmpShowServlet");
		}
	}

}
